
package com.jf.cloud.service.sysmanager.dao.impl;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.dao.DataAccessException;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.RowMapper;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.jf.cloud.service.sysmanager.common.base.BaseService;
import com.jf.cloud.service.sysmanager.common.base.GenericsUtils;
import com.jf.cloud.service.sysmanager.common.db.BaseDao;
import com.jf.cloud.service.sysmanager.common.db.Condition;
import com.jf.cloud.service.sysmanager.common.db.Query;
import com.jf.cloud.service.sysmanager.dao.IPubgBaseTypeService;
import com.jf.cloud.service.sysmanager.entity.PubgBaseType;


/**
 * 员工服务实现
 * 
 * @author 绝峰代码机1.0 创建时间：2018-03-31
 */
@Service("pubgBaseTypeService")
public class PubgBaseTypeServiceImpl extends BaseService<PubgBaseType, Long> implements IPubgBaseTypeService {

	/**
	 * 日志
	 */
	private static Log log = LogFactory.getLog(PubgBaseTypeServiceImpl.class);

	/**
	 * JPA公共DAO
	 */
	@Resource
	private BaseDao baseDao;

	private RowMapper<PubgBaseType> rowMapper = new BeanPropertyRowMapper<PubgBaseType>(GenericsUtils.getSuperClassGenricType(this.getClass()));

	/**
	 * 根据主键查询员工
	 * 
	 * @author 绝峰代码机1.0 创建时间：2018-03-31
	 */
	public PubgBaseType findPubgBaseType(Long rowId) throws Exception {
		try {
			return this.baseDao.findObject("", rowMapper, rowId);
		} catch (Exception e) {
			throw new Exception("根据主键查询员工出错！", e);
		}
	}

	/**
	 * 根据查询条件获取员工列表
	 * 
	 * @author 绝峰代码机1.0 创建时间：2018-03-31
	 */
	public List<PubgBaseType> findPubgBaseTypeList(Condition qc) throws Exception {
		try {
			return this.baseDao.findList("", rowMapper);
		} catch (Exception e) {
			throw new Exception("根据查询条件获取员工列表出错！", e);
		}
	}

	/**
	 * 新增/修改员工
	 * 
	 * @author 绝峰代码机1.0 创建时间：2018-03-31
	 */
	@Transactional
	public PubgBaseType saveOrUpdatePubgBaseType(PubgBaseType pubgBaseType) throws Exception {
		try {
			return this.baseDao.saveAll(pubgBaseType);
		} catch (Exception e) {
			throw new Exception("新增/修改员工出错！", e);
		}
	}

	/**
	 * 获取下拉框数据
	 * 
	 * @author 朱建文 创建时间：2018年4月3日 下午8:35:39
	 */
	public List<Map<String, Object>> selectDataMaps(String value, String label, Query query) {
		List<Map<String, Object>> datalList = new ArrayList<Map<String,Object>>();
		try {
			String sql = "SELECT " + value + " value, " + label + " label FROM pubg_base_type ";
			sql = query.getSQL(sql);
			datalList = this.baseDao.findMapList(sql, query.getParamList().toArray());
		} catch (DataAccessException e) {
			log.error("获取下拉框数据出错！", e);
		}
		return datalList;
	}
}
